import java.util.*;
public class RamdomObjs {
    public String equation(int n) {
        StringBuffer Bf = new StringBuffer(200);
        int i,roll;
        Random rand = new Random();
        roll = rand.nextInt(10)+1;
        Bf.append(roll);
        for(i=0; i< 2*n; i++){
            if(i % 2 == 1){
                roll = rand.nextInt(10)+1;
                Bf.append(roll);
            }
            else{
                roll = rand.nextInt(4)+1;
                switch (roll){
                    case 1:Bf.append('+');break;
                    case 2:Bf.append('-');break;
                    case 3:Bf.append('x');break;
                    case 4:Bf.append('/');break;
                }
            }
        }
        roll = rand.nextInt(n/2)+1;
        Bf.insert(2*roll,'(');
        String s = new String(Bf);
        return s;
    }
    public String testequation(int n) {
        char ch[] = new char[2*n];
        int a[] = new int[n+1];
        int i,j,k=0,roll;
        Random rand = new Random();
        for(i = 0; i<n+1; i++){
            a[i] = rand.nextInt(10)+1;
        }
        for(i = 0; i<n; i++){
            roll = rand.nextInt(4)+1;
            switch (roll){
                case 1: ch[i] = '+';break;
                case 2: ch[i] = '-';break;
                case 3: ch[i] = 'x';break;
                case 4: ch[i] = '/';break;
            }
        }
        int flag[];
        flag = new int[n+1];
        for (i=0; i<n+1; i++) {
            flag[i] = 1;
        }
        for (i=0; i<4; i++) {
            roll = rand.nextInt(n)+1;
            j = 0;
            while (j<roll){
                if(flag[k%n] == 1){
                    j++;
                }
                k++;
            }
            flag[(k-1)%n] = 0;
            k = 0;
        }
        j = 1;
        StringBuffer SB = new StringBuffer();
        for (i = 0; i<n+1; i++){
            if(flag[i] == 0){
                if(j%2 == 1){
                    SB.append('(');
                    SB.append(a[i]);
                    System.out.printf("(%d",a[i]);
                }
                else {
                    SB.append(a[i]);
                    SB.append(')');
                    System.out.printf("%d)",a[i]);
                }
                j++;
            }
            else {
                SB.append(a[i]);
                System.out.printf("%d",a[i]);
            }
            if(i<n){
                SB.append(ch[i]);
                System.out.printf("%c",ch[i]);
            }
        }
        String s = new String(SB);
        System.out.printf("\n");
        return s;
    }
    public void testequation1(int n){
        int i = 0,j = 0,num = 0,totalnum = 0;
        int a[] = new int[2*n+1];
        char ch[] = new char[2*n+1];
        Random rand = new Random();
        StringBuffer SB = new StringBuffer(4*n);
        while (i<2*n+1){
            if (num > 1 && totalnum < n+1) {
                if (rand.nextInt(2) == 0) {
                    a[i] = rand.nextInt(10) + 1;
                    SB.append(a[i]);
                    totalnum++;
                    num++;
                }
                else {
                    switch (rand.nextInt(4)+1){
                        case 1: ch[i] = '+';break;
                        case 2: ch[i] = '-';break;
                        case 3: ch[i] = 'x';break;
                        case 4: ch[i] = '/';break;
                    }
                    a[i] = 0;
                    SB.append(ch[i]);
                    num --;
                }
            }
            else if (num < 2) {
                a[i] = rand.nextInt(10) + 1;
                SB.append(a[i]);
                totalnum++;
                num++;
            }
            else  {
                switch (rand.nextInt(4)+1){
                    case 1: ch[i] = '+';break;
                    case 2: ch[i] = '-';break;
                    case 3: ch[i] = 'x';break;
                    case 4: ch[i] = '/';break;
                }
                a[i] = 0;
                SB.append(ch[i]);
            }
            i++;
        }
        String s = new String(SB);
        System.out.println(s);
    }
}
